import $ from 'jquery'

import Vue from 'vue'
import resource from 'vue-resource'
Vue.use(resource)

import 'bootstrap/dist/css/bootstrap.css'
import './css/base.css'
import './css/index.css'
import './cast.ico'

var vm = new Vue({
    el: '#app',
    data: {
        msg: 123,
        ret: {},
        day: {},
        tem1: '',
        cast1: '',
        tem2: '',
        cast2: '',
        all: {},
        all_day: {},
        provinces: '',
        city: '',
        rand: {}

    },
    methods: {
        show() {
            // 发送jsonp请求
            setInterval(

                this.$http.jsonp(
                    'https://wis.qq.com/weather/common', {
                        params: {
                            source: 'pc',
                            // weather_type: 'forecast_24h',
                            weather_type: 'forecast_1h|forecast_24h',
                            province: this.provinces,
                            city: this.city
                        }
                    }).then(res => {
                    this.rand = res.body.data.forecast_24h;
                    // console.log(res.body.data.forecast_24h);
                    if (Object.keys(this.rand).length != 0) {
                        this.all = res.body.data.forecast_24h
                        this.ret = res.body.data.forecast_24h
                        this.all_day = res.body.data.forecast_1h
                        this.day = res.body.data.forecast_1h
                    } else {
                        alert('请输入正确的省份和城市')
                    }
                    // res.body.data.forecast_24h


                    // console.log(res.body.data.forecast_24h);
                }), 300000)

        },
        dateFormat(date) {
            var year = date.substr(0, 4);
            var month = date.substr(4, 2);
            var day = date.substr(6, 2);
            var hour = date.substr(8, 2);
            var minute = date.substr(10, 2);
            var seconds = date.substr(12, 2);

            return year + '年' + month + '月' + day + '日' + hour + '时' + minute + '分' + seconds + '秒';
        },
        serach1() {
            // 第一一个空对象
            var newRet = [];
            this.ret = this.all;
            // 通过数组的indexOf方法实现
            Object.keys(this.ret).forEach(item => {
                // console.log(this.ret[item].max_degree);
                // console.log(this.ret[item].max_degree.indexOf(tem1) != -1);
                // console.log(this.ret[item].max_degree.includes(this.tem1));
                if (this.ret[item].max_degree.includes(this.tem1)) {
                    // newRet.assign(this.ret[item]);
                    // this.ret.push = this.ret[item];
                    // newRet[item] = this.ret[item];
                    newRet.push(this.ret[item])
                        // console.log(this.ret[item]);
                }
            })
            this.ret = newRet
            console.log(newRet);

        },
        serach2() {
            // 第一一个空对象
            var newRet = [];
            this.ret = this.all;
            // 通过数组的indexOf方法实现
            Object.keys(this.ret).forEach(item => {
                // console.log(this.ret[item].max_degree);
                // console.log(this.ret[item].max_degree.indexOf(tem1) != -1);
                // console.log(this.ret[item].max_degree.includes(this.tem1));
                if (this.ret[item].day_weather_short.includes(this.cast1)) {
                    // newRet.assign(this.ret[item]);
                    // this.ret.push = this.ret[item];
                    // newRet[item] = this.ret[item];
                    newRet.push(this.ret[item])
                        // console.log(this.ret[item]);
                }
            })
            this.ret = newRet
            console.log(newRet);
        },
        serach3() {
            // 第一一个空对象
            var newRet = [];
            this.day = this.all_day;
            // 通过数组的indexOf方法实现
            Object.keys(this.day).forEach(item => {
                // console.log(this.ret[item].max_degree);
                // console.log(this.ret[item].max_degree.indexOf(tem1) != -1);
                // console.log(this.ret[item].max_degree.includes(this.tem1));
                if (this.day[item].degree.includes(this.tem2)) {
                    // newRet.assign(this.ret[item]);
                    // this.ret.push = this.ret[item];
                    // newRet[item] = this.ret[item];
                    newRet.push(this.day[item])
                        // console.log(this.ret[item]);
                }
            })
            this.day = newRet
            console.log(newRet);
        },
        serach4() {
            // 第一一个空对象
            var newRet = [];
            this.day = this.all_day;
            // 通过数组的indexOf方法实现
            Object.keys(this.day).forEach(item => {
                // console.log(this.ret[item].max_degree);
                // console.log(this.ret[item].max_degree.indexOf(tem1) != -1);
                // console.log(this.ret[item].max_degree.includes(this.tem1));
                if (this.day[item].weather.includes(this.cast2)) {
                    // newRet.assign(this.ret[item]);
                    // this.ret.push = this.ret[item];
                    // newRet[item] = this.ret[item];
                    newRet.push(this.day[item])
                        // console.log(this.ret[item]);
                }
            })
            this.day = newRet
            console.log(newRet);
        },
        serachcity() {
            this.show()
        },
        serach_a() {
            this.show()
        }
    },
    // created: function() {
    //     this.show();
    //     // this.dateFormat(date);
    // }
})